﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Diagnostics;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;

namespace NaviQuest_v2
{
    public partial class NaviControl : Form
    {
        /*------------NaviQuest Basic Functions ------------*/
        #region
        //Handle Custom Events
        public void CustomEventHandlers()
        {
            //If the search box is double-clicked
            search_quest_input_box.DoubleClick += NaviControl_Clear_Quest_Search;
            search_quest_input_box.KeyPress += new KeyPressEventHandler(NaviControl_Search_Quests);
            //When the Quest List has been double clicked (Quest selected)
            quest_list.DoubleClick += quest_list_DoubleClick;
            //Handle minor actions based on selected tab
            control_tabs.SelectedIndexChanged += NaviControl_Tab_Changed;
            //Handle minor actions when Log text changes
            NaviControl_Message_Log.TextChanged += NaviControl_Scroll_Log;
            //Handle Log Button Clicks
            NaviControl_Message_Clear_btn.Click += (obj, x) => { NaviControl_Message_Log.Clear(); };
            NaviControl_Message_Save_btn.Click += (obj, x) => { NaviControl_Record_Log(); };
            //Handle search filter preference saving
            search_filter_id.CheckedChanged += (obj, x) => { NaviControl_Save_Search_Filter(); };
            search_filter_name.CheckedChanged += (obj, x) => { NaviControl_Save_Search_Filter(); };
            search_filter_lv.CheckedChanged += (obj, x) => { NaviControl_Save_Search_Filter(); };
            search_filter_summary.CheckedChanged += (obj, x) => { NaviControl_Save_Search_Filter(); };
            //When the quest start description is initially displayed
            //grab it and replace html formatting for rft acceptable
            //formatting
            basic_quest_start_desc.TextChanged += (obj, x) => { NaviControl_Format_Description(); };
            //Handle user changing a quest objective Name
            quest_obj_1_name_box.SelectedIndexChanged += (obj, x) => {

                //Define the string to be checked/cleaned
                String output_name_string = quest_obj_1_name_box.Text;

                //Define the current Quest ID as a point of reference
                int current_quest_id = Convert.ToInt32(quest_obj_1_id_box.Text);

                //If the output string is not empty
                if (!string.IsNullOrEmpty(output_name_string))
                {
                    //Create a datarow to fetch info specific to the newly selected Objective
                    DataRow selectedDataRow = ((DataRowView)quest_obj_1_name_box.SelectedItem).Row;
                    int objective_id = Convert.ToInt32(selectedDataRow["item_id"]);
                    //Update the id box with the newly selected data
                    quest_obj_1_id_box.Text = objective_id.ToString();
                }

                //If the currently selected text does not contain the default value
                if (!quest_obj_1_name_box.SelectedText.Contains("System.Data.DataRowView")) //The initial value for a field
                {
                    //Create a datarow to fetch info specific to the newly selected Objective
                    //Create a datarow to fetch info specific to the newly selected Objective
                    DataRow selectedDataRow = ((DataRowView)quest_obj_1_name_box.SelectedItem).Row;
                    String desc_string = selectedDataRow["item_desc"].ToString();
                    String output_desc_string = NaviControl_Clean_String(desc_string);

                    quest_obj_1_desc.Text = output_desc_string;
                }
            };

            //Handle minor action when the program closes
            this.FormClosed += (obj, x) => {
                //When the form is closed disable the Memory Switch
                //to avoid accessing disposed objects exception
                NaviControl_Disable_MemSwitch();
            };

            //Set Tooltip Arguments
            NaviControl_Tooltip();
        }

        public void NaviControl_Format_Description()
        {
            if (start_desc.Contains("<BR>") || start_desc.Contains("<br>"))
            {
                string new_string = start_desc.Replace("<br>", "\n\n");

                basic_quest_start_desc.Text = new_string;
            }
        }

        //Set Tooltip Related Arguments and Info
        public void NaviControl_Tooltip()
        {
            //Set tooltip arguments
            tooltip.AutoPopDelay = 50000000;
            tooltip.IsBalloon = true;
            tooltip.ToolTipTitle = "Information";
            tooltip.ToolTipIcon = ToolTipIcon.Info;

            //Set "Quest Search" tooltips
            tooltip.SetToolTip(search_quest_lb, "\nNaviQuest will automatically select the closest result as you type a search term, make sure to keep the search term short.\n\nExample:\nIf you are seeking any quest with the name \"Abhuva\" only search Abhu and press enter to scroll through available result. But if searching for \"Defeat Abhuva!\" simply type it's full name.");
            tooltip.SetToolTip(search_quest_input_box, "\nNaviQuest will automatically select the closest result as you type a search term, make sure to keep the search term short.\n\nExample:\nIf you are seeking any quest with the name \"Abhuva\" only search Abhu and press enter to scroll through available result. But if searching for \"Defeat Abhuva!\" simply type it's full name.");

        }
        
        //Clear searchbox text on click
        public void NaviControl_Clear_Quest_Search(object sender, EventArgs e)
        {
            if (control_tabs.SelectedIndex == 0)
            {
                search_quest_input_box.Text = "";
                quest_list.Rows[0].Selected = true;
                quest_list.FirstDisplayedScrollingRowIndex = 0;
            }
        }

        //First Launch Check
        public string NaviControl_First_Use_Check()
        {
            //If first_time returns as "true" || 1st Launch
            if (first_time == "true")
            {
                return "true";
            }
            //If first_time returns as "false" || 2nd+ Launch
            if (first_time == "false")
            {
                return "false";
            }
            return "error_001";
        }
        #endregion

        /*------------NaviQuest Memory Collection ------------*/
        #region
        //Convert the Raw Value from the
        //memory usage collector and then
        //report it back to the UI
        static string ConvertSize(Int64 value)
        {
            //Converted Size Array
            string[] SizeSuffixes = { "bytes", "KB", "MB" };

            //Convert the input 
            int mag = (int)Math.Log(value, 1024);
            decimal adjustedSize = (int)value / (1 << (mag * 10));

            //Return converted number for display
            return string.Format("{0} {1}", adjustedSize, SizeSuffixes[mag]);
        }

        //Collect the amount of memory (ram) NaviQuest is consuming
        public void NaviControl_Memory_Collector(object sender, DoWorkEventArgs e)
        {

            while (mem_collector_engaged == true)
            {
                //Put a delay to the thread to slow
                //down number output
                Thread.Sleep(500);

                //Fetch the current process
                Process current_mem_used = System.Diagnostics.Process.GetCurrentProcess();

                //Fetch memory used from current process
                long totalBytesOfMemoryUsed = current_mem_used.WorkingSet64;

                //Convert the Raw Value (B) of memory used
                //into a KB/MB form
                string result = ConvertSize(totalBytesOfMemoryUsed);

                try
                {
                    this.Invoke(new MethodInvoker(delegate { NaviControl_Mem_Used_Box.Text = result; }));
                }
                catch
                {
                    MessageBox.Show("Debug Message");
                }
            }
        }
        #endregion

        /*------------NaviQuest List Loader ------------*/
        #region
        //Internal List Loader]
        private void NaviControl_Internal_List_Loader(object sender, DoWorkEventArgs e)
        {
            NaviControl_Update_Log("text", 2, "==================================================");
            NaviControl_Update_Log("text", 1, "Internal Loader Responses:");
            NaviControl_Update_Log("text", 1, "==================================================");
            NaviControl_Update_Log("", 1, "");

            //Define Loader Callback
            string result = NaviControl_Internal_Loader();

            /* ------------- Error Reporting -------------*/
            #region

            //If an error is encountered during 
            //loading lists
            if (result.Contains("error"))
            {
                this.Invoke(new MethodInvoker(delegate { this.Text = "NaviQuest Editor"; }));

                NaviControl_Update_Log("text", 2, "=======================================");
                NaviControl_Update_Log("text", 1, "Errors Detected!");
                NaviControl_Update_Log("text", 1, "=======================================");
                NaviControl_Update_Log("text", 1, "Loader Response:");
                NaviControl_Update_Log("text", 1, "==================");
                NaviControl_Update_Log("", 1, "");
                NaviControl_Update_Log("text", 1, result);

                MessageBox.Show(ParentForm, "Error encountered while loading internal lists\n\nCheck the Log tab for more information", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            NaviControl_Update_Log("text", 2, "==================================================");

            #endregion
        }
        #endregion

        /*------------NaviControl Tab Functions------------*/
        #region
        //Switch NaviControls Tab
        public void NaviControl_Tab_Focus(int index)
        {
            //Set NaviControl.ControlTabs to the provided index
            control_tabs.SelectTab(index);
        }

        //Clean Up Tab Specific Data
        public void NaviControl_Tab_Cleaner(int tab_index)
        {
            this.Invoke(new MethodInvoker(delegate
            {

                //If the tab is "Basic Info"
                if (tab_index == 1)
                {
                    //To avoid bugs clear all previous entries
                    basic_quest_id.Text = "";
                    basic_quest_name.Text = "";
                    basic_quest_repeatable.Checked = false;
                    basic_quest_timed.Checked = false;
                    basic_quest_time_limit.Text = "";
                    basic_quest_limit_asura.Checked = false;
                    basic_quest_limit_deva.Checked = false;
                    basic_quest_limit_gaia.Checked = false;
                    basic_quest_limit_fighter.Checked = false;
                    basic_quest_limit_magician.Checked = false;
                    basic_quest_limit_summoner.Checked = false;
                    basic_quest_limit_hunter.Checked = false;

                }
                if (tab_index == 2)
                {
                    start_npc1_name_box.Text = "";
                    start_npc1_name_box.DataSource = null;
                    start_npc1_name_box.Items.Clear();
                    start_npc1_lua_box.Text = "";
                    start_npc1_x_box.Text = "";
                    start_npc1_y_box.Text = "";

                    start_npc2_name_box.Text = "";
                    start_npc2_name_box.DataSource = null;
                    start_npc2_name_box.Items.Clear();
                    start_npc2_lua_box.Text = "";
                    start_npc2_x_box.Text = "";
                    start_npc2_y_box.Text = "";

                    start_npc3_name_box.Text = "";
                    start_npc3_name_box.DataSource = null;
                    start_npc3_name_box.Items.Clear();
                    start_npc3_lua_box.Text = "";
                    start_npc3_x_box.Text = "";
                    start_npc3_y_box.Text = "";

                    end_npc_name_box.Text = "";
                    end_npc_name_box.DataSource = null;
                    end_npc_name_box.Items.Clear();
                    end_npc_lua_box.Text = "";
                    end_npc_x_box.Text = "";
                    end_npc_y_box.Text = "";
                }
            }));
        }

        //NaviControl Tab has changed clean and populate
        public void NaviControl_Tab_Changed(object sender, EventArgs e)
        {
            /* ------- About Info -------*/
            #region
            if (control_tabs.SelectedIndex == 6)
            {
                NaviControl_Tab_Populator(6);
            }
            #endregion
        }

        //Populate Tab being called
        public void NaviControl_Tab_Populator(int tab_index)
        {
            //Since this function may be called from any thread, let's make sure to have a delegate
            //just in-case/
            this.Invoke(new MethodInvoker(delegate
            {
                //Basic Info Tab
                #region
                if (tab_index == 1)
                {
                    //Begin populating input boxes with loaded data
                    basic_quest_id.Text = id.ToString();
                    basic_quest_name.Text = name;
                    basic_quest_type.Text = type;

                    //Check the appropriate "Limit" race boxes
                    if (limit_asura == 1 || limit_deva == 1 || limit_gaia == 1)
                    {
                        if (limit_asura == 1)
                        {
                            basic_quest_limit_asura.Checked = true;
                        }
                        if (limit_deva == 1)
                        {
                            basic_quest_limit_deva.Checked = true;
                        }
                        if (limit_gaia == 1)
                        {
                            basic_quest_limit_gaia.Checked = true;
                        }
                    }

                    //Check the appropriate "Limit" class boxes
                    if (limit_fighter == 1 || limit_magician == 1 || limit_summoner == 1 || limit_hunter == 1)
                    {
                        if (limit_fighter == 1)
                        {
                            basic_quest_limit_fighter.Checked = true;
                        }
                        if (limit_magician == 1)
                        {
                            basic_quest_limit_magician.Checked = true;
                        }
                        if (limit_summoner == 1)
                        {
                            basic_quest_limit_summoner.Checked = true;
                        }
                        if (limit_hunter == 1)
                        {
                            basic_quest_limit_hunter.Checked = true;
                        }
                    }

                    //If the quest is repeatable check the appropriate box
                    if (repeatable == 1)
                    {
                        basic_quest_repeatable.Checked = true;
                    }
                    //If the quest is timed check the appropriate box
                    if (time_limit_type == 1)
                    {
                        basic_quest_timed.Checked = true;
                        basic_quest_time_limit.Text = time_limit.ToString();
                        basic_quest_time_format.SelectedIndex = 0;
                    }
                    //Instead of displaying useless 0,
                    //translate them to "" or blankspace
                    //this gives us a cleaner Basic Info
                    //tab
                    if (script_start_text == "0")
                    {
                        basic_quest_start_script.Text = "";
                    }
                    else
                    {
                        basic_quest_start_script.Text = script_start_text;
                    }
                    if (script_end_text == "0")
                    {
                        basic_quest_end_script.Text = "";
                    }
                    else
                    {
                        basic_quest_end_script.Text = script_end_text;
                    }
                    basic_quest_start_desc.Text = start_desc;
                    basic_quest_mid_desc.Text = mid_desc;
                    basic_quest_end_desc.Text = end_desc;

                }
                #endregion

                //NPC Info Tab
                #region
                if (tab_index == 2)
                {

                    if (npc1_id != 0)
                    {
                        start_npc1_name_box.DataSource = npc_table;
                        start_npc1_name_box.DisplayMember = "name";
                        start_npc1_name_box.ValueMember = "id";

                        start_npc1_name_box.Text = npc1_name;
                        start_npc1_lua_box.Text = npc1_contact_script;
                        start_npc1_x_box.Text = npc1_x.ToString();
                        start_npc1_y_box.Text = npc1_y.ToString();

                        //Clean NPC1 Variables 
                        NaviControl_Clean_Variables("npc1");

                    }
                    if (npc2_id != 0)
                    {
                        npc_table2 = npc_table.Copy();

                        start_npc2_name_box.DataSource = npc_table2;
                        start_npc2_name_box.DisplayMember = "name";
                        start_npc2_name_box.ValueMember = "id";

                        start_npc2_name_box.Text = npc2_name;
                        start_npc2_lua_box.Text = npc2_contact_script;
                        start_npc2_x_box.Text = npc2_x.ToString();
                        start_npc2_y_box.Text = npc2_y.ToString();

                        //Clean NPC2 Variables 
                        NaviControl_Clean_Variables("npc2");
                    }
                    if (npc3_id != 0)
                    {
                        npc_table3 = npc_table.Copy();

                        start_npc3_name_box.DataSource = npc_table3;
                        start_npc3_name_box.DisplayMember = "name";
                        start_npc3_name_box.ValueMember = "id";

                        start_npc3_name_box.Text = npc3_name;
                        start_npc3_lua_box.Text = npc3_contact_script;
                        start_npc3_x_box.Text = npc3_x.ToString();
                        start_npc3_y_box.Text = npc3_y.ToString();

                        //Clean NPC3 Variables 
                        NaviControl_Clean_Variables("npc3");
                    }
                    if (end_npc_id != 0)
                    {
                        npc_table_end = npc_table.Copy();

                        end_npc_name_box.DataSource = npc_table_end;
                        end_npc_name_box.DisplayMember = "name";
                        end_npc_name_box.ValueMember = "id";

                        end_npc_name_box.Text = end_npc_name;
                        end_npc_lua_box.Text = end_npc_contact_script;
                        end_npc_x_box.Text = end_npc_x.ToString();
                        end_npc_y_box.Text = end_npc_y.ToString();

                        //Clean End NPC Variables 
                        NaviControl_Clean_Variables("end");
                    }
                }
                #endregion

                //Objective Info Tab
                #region

                if (tab_index == 3)
                {
                    if (type.ToLower().Contains("item"))
                    {
                        if (quest_obj_id1 != 0)
                        {
                            if (!string.IsNullOrEmpty(quest_obj_name1))
                            {
                                quest_obj_1_id_box.Text = quest_obj_id1.ToString();
                                quest_obj_1_name_box.DataSource = item_objectives_table;
                                quest_obj_1_name_box.DisplayMember = "item_name";
                                quest_obj_1_name_box.ValueMember = "item_id";
                                quest_obj_1_name_box.Text = quest_obj_name1;
                                quest_obj_1_desc.Text = NaviControl_Clean_String(quest_obj_desc1);
                                quest_obj_1_amount.Text = quest_obj_amt1.ToString();
                            }
                        }
                        if (quest_obj_id2 != 0)
                        {
                            if (!string.IsNullOrEmpty(quest_obj_name2))
                            {
                                item_objectives_table1 = item_objectives_table.Copy();

                                quest_obj_2_id_box.Text = quest_obj_id2.ToString();
                                quest_obj_2_name_box.DataSource = item_objectives_table1;
                                quest_obj_2_name_box.DisplayMember = "item_name";
                                quest_obj_2_name_box.ValueMember = "item_id";
                                quest_obj_2_name_box.Text = quest_obj_name2;
                                quest_obj_2_desc.Text = NaviControl_Clean_String(quest_obj_desc2);
                                quest_obj_2_amount.Text = quest_obj_amt1.ToString();
                            }
                        }
                    }
                }

                #endregion

                //About Tab
                #region
                if (tab_index == 6)
                {
                    NaviQuest_About_Menu.ReadOnly = true;
                    NaviQuest_About_Menu.Text = "Hello User,\n\nNaviQuest is an Open-Source Rappelz Quest Editor intended to make editing quests as easy and save as possible. This program is credited to it's coder iSmokeDrow and all those who have ever taught him or inspired him to do projects like these!\n\nNaviQuest is entirely free and should never be sold at all! If you find this program being sold or spread without credit to iSmokeDrow and associates please report it to iSmokeDrow@gmail.com\n\nYou can redistribute this program with proper credits but please do not remove the Teal Sky Development Back-Link!\n\nEnjoy!";
                }
                #endregion

            }));
        }
        #endregion

        /* ------------- NaviControl Misc Functions ------------- */
        #region
        
        //Clean input strings of html and other unwanted syntax
        public string NaviControl_Clean_String(String input_string)
        {
            //Define the index to clean the "Weight" from holder
            int weight_idx = 0;
            string final_string = "";

            string return_string = input_string.Replace("<BR>", "").Replace("<br>", "").Replace("<b>", "").Replace("</b>", "").Replace("<size:4>", "").Replace("<SIZE:4>","").Replace("<size:10>", "").Replace("<size:13>", "").Replace("#@itemname@#", "");
            if (return_string.Contains("Weight :"))
            {
                //define the actual index
                weight_idx = return_string.IndexOf("Weight :");
                //Create the edited string to send back
                final_string = return_string.Remove(weight_idx);
            }
            //Send back the edited string
            return final_string;
        }

        //Gather START/PROGRESS/END npc_id's
        public string NaviControl_NPC_ID_Collector(Int32 quest_ID)
        {
            //To avoid bugs reset the npc counter
            start_npc_count = 0;

            //Loop through each questlink for info
            foreach (DataRow row in questlink_table.Rows)
            {
                //Define Variables
                int qid = row.Field<Int32>("id");
                int qlink_npc_id = row.Field<Int32>("npc_id");
                int flag_start = row.Field<Int32>("flag_start");
                int flag_progress = row.Field<Int32>("flag_progress");
                int flag_end = row.Field<Int32>("flag_end");

                //If the row being searched has an identical id
                //to that of the quest being viewed, it should
                //be checked further
                if (qid == id)
                {
                    //If the field has a flag_start-end checked it
                    //for start/progress/end npc's
                    if (flag_start == 1 || flag_progress == 1 || flag_end == 1 )
                    {
                        //If the row contains between 1-3 Starting NPC
                        if (flag_start == 1)
                        {
                            //Make sure there is only 3 or below
                            //Starting NPC
                            if (start_npc_count < 4)
                            {
                                //For every NPC log it to the count
                                start_npc_count++;
                            }
                            //If this is the first start npc 
                            //being recorded
                            if (start_npc_count == 1)
                            {
                                npc1_id = qlink_npc_id;
                            }
                            //If this is the second start npc
                            //being recorded
                            if (start_npc_count == 2)
                            {
                                npc2_id = qlink_npc_id;
                            }
                            //If this is the third start npc 
                            //being recorded
                            if (start_npc_count == 3)
                            {
                                npc3_id = qlink_npc_id;
                            }
                        }
                        //If the row contains a Progress NPC  
                        if (flag_progress == 1)
                        {
                        }
                        //If the row contains an END NPC
                        if (flag_end == 1)
                        {
                            end_npc_id = qlink_npc_id;
                        }
                    }
                    //If the questlink info has all flags
                    if (flag_start == 1 && flag_progress == 1 && flag_end == 1)
                    {
                        MessageBox.Show("This NPC is all points START/PROGRESS/END " + qlink_npc_id);
                    }
                }
            }
            return "internal_data_collector_success";
        }

        //Gather START NPC (1-3) Info
        public string NaviControl_NPC_INFO_Collector(Int32 npc1_ID, Int32 npc2_ID, Int32 npc3_ID, Int32 end_npc_ID)
        {
            //Define DataRows to store NPC Data
            DataRow npc1_result;
            DataRow npc2_result;
            DataRow npc3_result;
            DataRow end_npc_result;

            NaviControl_Update_Log("text", 2, "-------------------------------------------------------");
            NaviControl_Update_Log("text", 1, "Collecting NPC Info:");
            NaviControl_Update_Log("text", 1, "-------------------------------------------------------");
            NaviControl_Update_Log("", 1, "");

            //Attempt to load npc info result based on previously fetched npc_id
            try
            {
                //if the 1st NPC ID isn't 0
                if (npc1_id != 0)
                {
                    try
                    {
                        //Load the npc1 row with info matching the npc's ID
                        npc1_result = npc_table.AsEnumerable().Where(row => row.Field<Int32>("id") == npc1_ID).FirstOrDefault();

                        npc1_name = npc1_result.Field<String>("name");
                        npc1_contact_script = npc1_result.Field<String>("contact_script");
                        npc1_x = npc1_result.Field<Int32>("x");
                        npc1_y = npc1_result.Field<Int32>("y");

                        NaviControl_Update_Log("text", 1, "Start NPC "+npc1_ID+" : "+ npc1_name +" Loaded");
                    }
                    catch (Exception ex)
                    {
                        NaviControl_Update_Log("text", 1, "Start NPC "+npc1_ID+" Load Failed!");
                        MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                if (npc2_id != 0)
                {
                    try
                    {
                        npc2_result = npc_table.AsEnumerable().Where(row => row.Field<Int32>("id") == npc2_ID).FirstOrDefault();

                        npc2_name = npc2_result.Field<String>("name");
                        npc2_contact_script = npc2_result.Field<String>("contact_script");
                        npc2_x = npc2_result.Field<Int32>("x");
                        npc2_y = npc2_result.Field<Int32>("y");

                        NaviControl_Update_Log("text", 1, "Start NPC (2) " + npc2_ID + " : " + npc2_name + " Loaded");

                    }
                    catch (Exception ex)
                    {
                        NaviControl_Update_Log("text", 1, "Start NPC (2) " + npc1_ID + " Load Failed!");
                        MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                if (npc3_id != 0)
                {
                    try
                    {
                        npc3_result = npc_table.AsEnumerable().Where(row => row.Field<Int32>("id") == npc3_ID).FirstOrDefault();

                        npc3_name = npc3_result.Field<String>("name");
                        npc3_contact_script = npc3_result.Field<String>("contact_script");
                        npc3_x = npc3_result.Field<Int32>("x");
                        npc3_y = npc3_result.Field<Int32>("y");

                        NaviControl_Update_Log("text", 1, "Start NPC (3) " + npc3_ID + " : " + npc3_name + " Loaded");
                    }
                    catch (Exception ex)
                    {
                        NaviControl_Update_Log("text", 1, "Start NPC (3) " + npc3_ID + " Load Failed!");
                        MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                if (end_npc_id != 0)
                {
                    try
                    {
                        end_npc_result = npc_table.AsEnumerable().Where(row => row.Field<Int32>("id") == end_npc_ID).FirstOrDefault();

                        end_npc_name = end_npc_result.Field<String>("name");
                        end_npc_contact_script = end_npc_result.Field<String>("contact_script");
                        end_npc_x = end_npc_result.Field<Int32>("x");
                        end_npc_y = end_npc_result.Field<Int32>("y");

                        NaviControl_Update_Log("text", 1, "End NPC " + end_npc_id + " : "+ end_npc_name +" Loaded");
                    }
                    catch (Exception ex)
                    {
                        NaviControl_Update_Log("text", 1, "End NPC [" + end_npc_id + "] Load Failed!");
                        MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

                NaviControl_Update_Log("text", 1, "Quest NPC Info Variables Set");
            }
            catch
            {
                return "internal_npc_info_collector_unexpected_error";
            }

            return "internal_npc_info_collected";
        }

        //Clean Quest Related variables
        public void NaviControl_Clean_Variables(String variable_name)
        {
            if (variable_name == "npc1")
            {
                npc1_id = 0;
                npc1_name = "";
                npc1_contact_script = "";
                npc1_x = 0;
                npc1_y = 0;
            }
            if (variable_name == "npc2")
            {
                npc2_id = 0;
                npc2_name = "";
                npc2_contact_script = "";
                npc2_x = 0;
                npc2_y = 0;
            }
            if (variable_name == "npc3")
            {
                npc3_id = 0;
                npc3_name = "";
                npc3_contact_script = "";
                npc3_x = 0;
                npc3_y = 0;
            }
            if (variable_name == "end")
            {
                end_npc_id = 0;
                end_npc_name = "";
                end_npc_contact_script = "";
                end_npc_x = 0;
                end_npc_y = 0;
            }
        }

        //Format the Quest List
        public void NaviControl_Format_Quests()
        {
            //Adjust quest_list column size
            this.Invoke(new MethodInvoker(delegate
            {
                quest_list.Columns[0].Width = 40;
                quest_list.Columns[1].Width = 190;
                quest_list.Columns[2].Width = 30;
                quest_list.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

                //To avoid bugs auto-select first result
                quest_list.Rows[0].Selected = true;
                quest_list.FirstDisplayedScrollingRowIndex = 0;
            }));
        }

        //Update the NaviControl Progress Bar
        public void NaviControl_Update_Progressbar(Int32 maxVal, Int32 curVal)
        {
            if (maxVal != 0)
            {
                //Set the NaviControl Progressbar Max Value to Total Quest Amount
                this.Invoke(new MethodInvoker(delegate { NaviControl_Progress.Maximum = maxVal; }));
            }

            if (curVal == 1)
            {
                //Set the NaviControl Progressbar value to 1
                this.Invoke(new MethodInvoker(delegate { NaviControl_Progress.Value = 1; }));
            }
            else
            {
                this.Invoke(new MethodInvoker(delegate { if (NaviControl_Progress.Value != NaviControl_Progress.Maximum) { NaviControl_Progress.Value++; } }));
            }

        }

        //Collect the total amount of lines in all internal lists
        public static int NaviControl_Collect_Lists_Total()
        {
            //Using the Internal Quest Total Reader
            using (StreamReader r = internal_quest_total_reader)
            {
                //While the reader is operating add each row found to the total
                while (r.ReadLine() != null) { quest_total++; }           
            }
            using (StreamReader r = internal_questlink_total_reader)
            {
                while (r.ReadLine() != null) { questlink_total++; }
            }
            using (StreamReader r = internal_basic_total_reader)
            {
                while (r.ReadLine() != null) { quest_basic_total++; }
            }
            using (StreamReader r = internal_npc_total_reader)
            {
                while (r.ReadLine() != null) { quest_npc_total++; }
            }
            using (StreamReader r = internal_item_objective_total_reader)
            {
                while (r.ReadLine() != null) { quest_item_objective_total++; }
            }

            int fin_total = quest_total + questlink_total + quest_basic_total + quest_npc_total + quest_item_objective_total;

            return fin_total;
        }

        //When log updates are received print them to the log box
        public void NaviControl_Update_Log(String type, int line_type, String update_text)
        {
            //Legend ===================================================

            //Type:
            // -- Initial = Very first log message
            // -- Text = A normal log message (2nd+ message)
            // -- Update = A status indicator, e.g. TEXT...OK 

            //Line Type:
            // -- 0 = Same Line
            // -- 1 = New Line
            // -- 2 = x2 New Lines

            //Update Text: The actual message being sent

            // =========================================================

            //Check to see if an actual message or just formatting
            //if there is a line_type but not an update_text consider
            //the call a formatting call
            if (string.IsNullOrEmpty(type) && line_type != 0 && string.IsNullOrEmpty(update_text))
            {
                if (line_type == 1)
                {
                    this.Invoke(new MethodInvoker(delegate { NaviControl_Message_Log.AppendText("\n"); }));
                }
                if (line_type == 2)
                {
                    this.Invoke(new MethodInvoker(delegate { NaviControl_Message_Log.AppendText("\n\n"); }));
                }
            }
            //If there is an actual message being sent
            else if (!string.IsNullOrEmpty(update_text))
            {
                //If the message is the first 
                if (type == "initial")
                {
                    this.Invoke(new MethodInvoker(delegate { NaviControl_Message_Log.Text = update_text; }));
                }
                //If the message is 2nd+
                if (type == "text")
                {
                    //If there are no new lines
                    if (line_type == 0)
                    {
                        this.Invoke(new MethodInvoker(delegate { NaviControl_Message_Log.AppendText(update_text); }));
                    }
                    //If there is 1 new line
                    if (line_type == 1)
                    {
                        this.Invoke(new MethodInvoker(delegate { NaviControl_Message_Log.AppendText("\n" + update_text); }));
                    }
                    //If there is 2 new lines
                    if (line_type == 2)
                    {
                        this.Invoke(new MethodInvoker(delegate { NaviControl_Message_Log.AppendText("\n\n" + update_text); }));
                    }
                }
                //If the message is an UPDATE to a previous TEXT
                if (type == "update")
                {
                    if (!string.IsNullOrEmpty(update_text))
                    {
                        this.Invoke(new MethodInvoker(delegate { NaviControl_Message_Log.AppendText(update_text); }));
                    }
                }
            }
        }

        //When the program closes record the current log to a physical file
        public void NaviControl_Record_Log()
        {
            //Define the root, folder directories and
            //the date+time and filename
            string dir = Directory.GetCurrentDirectory();
            string datetime = DateTime.Now.ToString();
            string folder_dir = dir+"\\Log\\";
            //Combine path + date
            string date_name = folder_dir + datetime.Replace("/", "-").Replace(":", "-").Replace(" AM", "am").Replace(" PM", "pm").Replace(" ", "_");
            //Combine newly created date_name + file extension (.txt)
            string file_name = date_name + ".txt";
            //Combine directory+filename together
            string final_path = Path.Combine(folder_dir, file_name);

            //Check if the Logs folder doesn't exist
            if (!Directory.Exists(folder_dir))
            {
                //Create the Log folder
                Directory.CreateDirectory(folder_dir);
            }

            //If the Log is not empty
            if (NaviControl_Message_Log.Text.Length != 0)
            {
                //Define the Writer for the Log
                StreamWriter log_writer = new StreamWriter(final_path);
                //Write the Log
                log_writer.Write(NaviControl_Message_Log.Text);
                //Close the Writer
                log_writer.Close();

                //Show user Success Message
                MessageBox.Show("Log Saved!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else //If the Log is empty
            {
                //Show user Failure Message
                MessageBox.Show("Nothing to save!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        //When the text changes in the log, make sure to scroll to the very end
        public void NaviControl_Scroll_Log(object sender, EventArgs e)
        {
            Point pt = NaviControl_Message_Log.GetPositionFromCharIndex(NaviControl_Message_Log.SelectionStart);
            if (pt.Y > NaviControl_Message_Log.Height)
            {
                NaviControl_Message_Log.ScrollToCaret();
            }

        }

        //In the event the memory collector needs to be disengaged
        public void NaviControl_Disable_MemSwitch()
        {
            mem_collector_engaged = false;

            NaviControl_Update_Log("text", 1, "Memory Usage Collector Stopped");
        }

        //When the NaviControl Search Filter is changed log the preference
        public void NaviControl_Save_Search_Filter()
        {
            if (search_filter_id.Checked == true)
            {
                Properties.Settings.Default.search_by_id = true;
            }
            if (search_filter_name.Checked == true)
            {
                Properties.Settings.Default.search_by_name = true;
            }
            if (search_filter_lv.Checked == true)
            {
                Properties.Settings.Default.search_by_lv = true;
            }
            if (search_filter_summary.Checked == true)
            {
                Properties.Settings.Default.search_by_summary = true;
            }
            //
            Properties.Settings.Default.Save();
        }

        //When NaviQuest Loads set the Search Filter based on previously selected preference
        public void NaviControl_Set_Search_Filter()
        {
            if (search_by_id == true)
            {
                search_filter_id.Checked = true;
            }
            if (search_by_name == true)
            {
                search_filter_name.Checked = true;
            }
            if (search_by_lv == true)
            {
                search_filter_lv.Checked = true;
            }
            if (search_by_summary == true)
            {
                search_filter_summary.Checked = true;
            }
            if (search_by_id == false
                && search_by_name == false
                && search_by_lv == false
                && search_by_summary == false)
            {
                search_filter_name.Checked = true;
            }
        }

        //Search the Quest List (ASYNC)
        public void NaviControl_Search_Quests(object sender, KeyPressEventArgs k)
        {
            //If the key being pressed is the Backspace key
            if (k.KeyChar == (char)Keys.Back)
            {
                //If the search text length is below or equal to 1
                if (search_quest_input_box.Text.Length >= 1)
                {
                    //Set the selected row of the Quest List back to default
                    quest_list.Rows[0].Selected = true;
                    quest_list.FirstDisplayedScrollingRowIndex = 0;
                }
            }
            else //Else the user must be searching
            {
                //Define the Amount of Rows Returned by search
                int result = quest_list.Rows.GetFirstRow(DataGridViewElementStates.Selected) + 1;

                //While the results returned is not 0
                while (result != 0)
                {
                    //Try to filter the list based on results
                    try
                    {
                        //If the user has opt'd to search by ID
                        if (search_filter_id.Checked == true)
                        {
                            //If the Search Result doesn't contain the search string
                            if (!quest_list.Rows[result].Cells[0].Value.ToString().ToLower().Contains(search_quest_input_box.Text.ToLower()))
                            {
                                //Add onto the result and keep going
                                result++;
                            }
                            else //The Search Result does contain the search string
                            {
                                //Set the Quest List Selected row accordingly
                                quest_list.FirstDisplayedScrollingRowIndex = result;
                                quest_list.Rows[result].Selected = true;
                                //Break the search loop
                                break;
                            }
                        }
                        //If the user has opt'd to search by Name
                        if (search_filter_name.Checked == true)
                        {
                            //If the Search Result doesn't contain the search string
                            if (!quest_list.Rows[result].Cells[1].Value.ToString().ToLower().Contains(search_quest_input_box.Text.ToLower()))
                            {
                                //Add onto the result and keep going
                                result++;
                            }
                            else //The Search Result does contain the search string
                            {
                                quest_list.FirstDisplayedScrollingRowIndex = result;
                                quest_list.Rows[result].Selected = true;
                                break;
                            }
                        }
                        if (search_filter_lv.Checked == true)
                        {
                            if (!quest_list.Rows[result].Cells[2].Value.ToString().ToLower().Contains(search_quest_input_box.Text.ToLower()))
                            {
                                result++;
                            }
                            else
                            {
                                quest_list.FirstDisplayedScrollingRowIndex = result;
                                quest_list.Rows[result].Selected = true;
                                break;
                            }
                        }
                        if (search_filter_summary.Checked == true)
                        {
                            if (!quest_list.Rows[result].Cells[3].Value.ToString().ToLower().Contains(search_quest_input_box.Text.ToLower()))
                            {
                                result++;
                            }
                            else
                            {
                                quest_list.FirstDisplayedScrollingRowIndex = result;
                                quest_list.Rows[result].Selected = true;
                                break;
                            }
                        }

                    }
                    catch
                    {
                        break;
                    }
                }                       
            }
        }

        //Called when a quest is selected
        public void NaviControl_Collect_Quest_Info(object sender, DoWorkEventArgs s)
        {
            //Send Informational Log Updates
            NaviControl_Update_Log("text", 1, "==================================================");
            NaviControl_Update_Log("text", 1, "Collecting information for Quest ID: " + tempID + "");
            NaviControl_Update_Log("text", 1, "==================================================");
            NaviControl_Update_Log("", 1, "");

            //If the basic info was loaded properly
            if (NaviControl_POPULATE_BASIC_Info() == "basic_info_loaded")
            {
                //Send Success Message
                NaviControl_Update_Log("text", 2, "Basic Info Collection Complete");
                NaviControl_Update_Log("text", 1, "-------------------------------------------------------");
            }
            else 
            {
                //Send Failure Message
                NaviControl_Update_Log("text", 2, "Basic Info Colletion Failed!");
                NaviControl_Update_Log("text", 1, "-------------------------------------------------------");
            }

            //If the npc info was loaded properly
            if (NaviControl_POPULATE_NPC_Info() == "npc_info_loaded")
            {
                //Send Success Message
                NaviControl_Update_Log("text", 2, "NPC Info Collection Complete");
                NaviControl_Update_Log("text", 1, "-------------------------------------------------------");

            }
            else
            {
                NaviControl_Update_Log("text", 2, "NPC Info Collection Failed!");
                NaviControl_Update_Log("text", 1, "-------------------------------------------------------");

            }

            if (NaviControl_POPULATE_OBJECTIVE_Info() == "objective_info_loaded")
            {
                //Send Success Message
                NaviControl_Update_Log("text", 2, "Objective Info Collection Complete");
                NaviControl_Update_Log("text", 1, "-------------------------------------------------------");
            }
            else
            {
                MessageBox.Show("Objective loading error");
            }

            NaviControl_Update_Log("text", 1, "==================================================");
        }

        //Basic Info Collector
        public string NaviControl_COLLECT_BASIC_Info()
        {

            if (tempID != 0)
            {
                //Attempt to load basic_info result based on previously fetched quest_id
                try
                {
                    basic_result = basic_table.AsEnumerable().Where(row => row.Field<Int32>("id") == tempID).FirstOrDefault();
                    NaviControl_Update_Log("text", 1, "Basic Info for "+basic_result.Field<String>("name")+ " Loaded");
                }
                catch
                {
                    MessageBox.Show(ParentForm, "Failed to fetch Basic Info!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return "basic_info_collector_unexpected_error || no basic info";
                }

                //Just to make sure that everything goes properly
                //We will place the populating method inside an if statement
                //If the result IS NOT empty continue!
                if (!basic_result.IsNull(0))
                {
                    //The Quest Type is INT by default, 
                    //but since we have a legend we 
                    //should convert it
                    if (basic_result.Field<String>("type") == "101")
                    {
                        basic_result.SetField<String>("type", "KILL_TOTAL");
                    }
                    if (basic_result.Field<String>("type") == "102")
                    {
                        basic_result.SetField<String>("type", "KILL_INDIVIDUAL");
                    }
                    if (basic_result.Field<String>("type") == "103")
                    {
                        basic_result.SetField<String>("type", "COLLECT");
                    }
                    if (basic_result.Field<String>("type") == "106")
                    {
                        basic_result.SetField<String>("type", "HUNT_ITEM");
                    }
                    if (basic_result.Field<String>("type") == "107")
                    {
                        basic_result.SetField<String>("type", "HUNT_ITEM_DROP");
                    }
                    if (basic_result.Field<String>("type") == "201")
                    {
                        basic_result.SetField<String>("type", "LEARN_SKILL");
                    }
                    if (basic_result.Field<String>("type") == "301")
                    {
                        basic_result.SetField<String>("type", "UPGRADE_ITEM");
                    }
                    if (basic_result.Field<String>("type") == "401")
                    {
                        basic_result.SetField<String>("type", "CONTACT");
                    }
                    if (basic_result.Field<String>("type") == "501")
                    {
                        basic_result.SetField<String>("type", "JOB_LEVEL");
                    }
                    if (basic_result.Field<String>("type") == "601")
                    {
                        basic_result.SetField<String>("type", "PARAMETER");
                    }
                    if (basic_result.Field<String>("type") == "901")
                    {
                        basic_result.SetField<String>("type", "RANDOM_KILL");
                    }
                    if (basic_result.Field<String>("type") == "902")
                    {
                        basic_result.SetField<String>("type", "RANDOM_COLLECT");
                    }

                    NaviControl_Update_Log("text", 1, "Quest Type Translated");

                    id = basic_result.Field<Int32>("id");
                    name = basic_result.Field<String>("name");
                    repeatable = basic_result.Field<Int32>("repeatable");
                    time_limit_type = basic_result.Field<Int32>("time_limit_type");
                    time_limit = basic_result.Field<Int32>("time_limit");
                    limit_asura = basic_result.Field<Int32>("limit_asura");
                    limit_deva = basic_result.Field<Int32>("limit_deva");
                    limit_gaia = basic_result.Field<Int32>("limit_gaia");
                    limit_fighter = basic_result.Field<Int32>("limit_fighter");
                    limit_magician = basic_result.Field<Int32>("limit_magician");
                    limit_summoner = basic_result.Field<Int32>("limit_summoner");
                    limit_hunter = basic_result.Field<Int32>("limit_hunter");
                    type = basic_result.Field<String>("type");
                    quest_obj_id1 = basic_result.Field<Int32>("value1");
                    quest_obj_amt1 = basic_result.Field<Int32>("value2");
                    quest_obj_id2 = basic_result.Field<Int32>("value3");
                    quest_obj_amt2 = basic_result.Field<Int32>("value4");
                    quest_obj_id3 = basic_result.Field<Int32>("value5");
                    quest_obj_amt3 = basic_result.Field<Int32>("value6");
                    quest_obj_id4 = basic_result.Field<Int32>("value7");
                    quest_obj_amt4 = basic_result.Field<Int32>("value8");
                    quest_obj_id5 = basic_result.Field<Int32>("value9");
                    quest_obj_amt5 = basic_result.Field<Int32>("value10");
                    quest_obj_id6 = basic_result.Field<Int32>("value11");
                    quest_obj_amt6 = basic_result.Field<Int32>("value12");
                    script_start_text = basic_result.Field<String>("script_start_text");
                    script_end_text = basic_result.Field<String>("script_end_text");
                    start_desc = basic_result.Field<String>("start_desc");
                    mid_desc = basic_result.Field<String>("mid_desc");
                    end_desc = basic_result.Field<String>("end_desc");

                    NaviControl_Update_Log("text", 1, "Quest Basic Info Variables Set");

                    return "basic_info_collection_complete";
                }
                else
                {
                    NaviControl_Update_Log("text", 1, "Quest Info for "+tempID+" Failed to Load!");
                    MessageBox.Show(ParentForm, "Proper Basic Info was not returned!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return "basic_info_collector_unexpected_error || missing basic info";
                }
            }
            else
            {
                return "basic_info_collector_unexpected_error || no quest id";
            }
        }

        //When called collect Basic Info
        //and populate the Basic Info tab
        public string NaviControl_POPULATE_BASIC_Info()
        {
            //Define the quest_id
            tempID = Convert.ToInt32(quest_list.SelectedRows[0].Cells[0].Value);

            //Launch Tab Cleaner on "Basic Tab"
            NaviControl_Tab_Cleaner(1);

            NaviControl_Update_Log("text", 1, "-------------------------------------------------------");
            NaviControl_Update_Log("text", 1, "Collecting Basic Info...");
            NaviControl_Update_Log("text", 1, "-------------------------------------------------------");
            NaviControl_Update_Log("", 1, "");


            if (NaviControl_COLLECT_BASIC_Info() == "basic_info_collection_complete")
            {
                //Populate Tab Info
                this.Invoke(new MethodInvoker(delegate { NaviControl_Tab_Populator(1); }));
            }

            this.Invoke(new MethodInvoker(delegate
            {
                //Set tooltip'd info
                tooltip.SetToolTip(basic_quest_repeatable, "Checking this will mark this quest as repeatable");
                tooltip.SetToolTip(basic_quest_timed, "Checking this will mark this quest as timed");
                tooltip.SetToolTip(basic_quest_script_area, "Start/End Scripts are LUA that are called at the Beginning/End of a quest (e.g. Taking a quest or Turning a quest in)");
                tooltip.SetToolTip(basic_quest_name, name);
            }));

            return "basic_info_loaded";
        }

        //When called collect NPC Info
        //and populate the NPC Info tab
        public string NaviControl_POPULATE_NPC_Info()
        {
            //Collect START/PROGRESS/END npc_id
            if (NaviControl_NPC_ID_Collector(id) == "internal_data_collector_success")
            {
                //Collect NPC Info based on npc_id
                if (NaviControl_NPC_INFO_Collector(npc1_id, npc2_id, npc3_id, end_npc_id) == "internal_npc_info_collected")
                {
                    //Clean the NPC Tab
                    NaviControl_Tab_Cleaner(2);
                    
                    //Populate NPC Info Tab
                    NaviControl_Tab_Populator(2);

                    //Set tooltip'd information
                    tooltip.SetToolTip(start_npc1_lua_box, npc1_contact_script);
                    tooltip.SetToolTip(start_npc2_lua_box, npc2_contact_script);
                    tooltip.SetToolTip(start_npc3_lua_box, npc3_contact_script);
                    tooltip.SetToolTip(end_npc_lua_box, end_npc_contact_script);

                    return "npc_info_loaded";
                }
                else
                {
                    NaviControl_Update_Log("update", 0, "FAIL");
                    MessageBox.Show("Failed to collect NPC Info!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            return "npc_loader_error";
        }

        public string NaviControl_POPULATE_OBJECTIVE_Info()
        {
            int qID = tempID;

            //if the 1st NPC ID isn't 0
            if (qID != 0)
            {
                if (type.ToLower().Contains("item"))
                {
                    //Load the npc1 row with info matching the npc's ID
                    objective_result = item_objectives_table.AsEnumerable().Where(row => row.Field<Int32>("item_id") == quest_obj_id1).FirstOrDefault();          

                    if (objective_result.Field<Int32>("item_id") != 0)
                    {
                        quest_obj_name1 = objective_result.Field<String>("item_name");
                        quest_obj_desc1 = objective_result.Field<String>("item_desc");
                    }
                    else
                    {
                        MessageBox.Show("No Objective Data (#1)");
                    }
                    if (objective_result.Field<Int32>("item_id") != 0)
                    {
                        quest_obj_name2 = objective_result.Field<String>("item_name");
                        quest_obj_desc2 = objective_result.Field<String>("item_desc");

                    }
                    else
                    {
                        MessageBox.Show("No Objective Data (#2)");
                    }
                    /*if (objective_result.Field<Int32>("objective_id3") != 0)
                    {
                        quest_obj_id3 = objective_result.Field<Int32>("objective_id3");
                        quest_obj_name3 = objective_result.Field<String>("objective_name3");
                        quest_obj_desc3 = objective_result.Field<String>("objective_desc3");
                        quest_obj_amt3 = objective_result.Field<Int32>("objective_amount3");
                    }
                    else
                    {
                        MessageBox.Show("No Objective Data (#3)");
                    }
                    if (objective_result.Field<Int32>("objective_id4") != 0)
                    {
                        quest_obj_id4 = objective_result.Field<Int32>("objective_id4");
                        quest_obj_name4 = objective_result.Field<String>("objective_name4");
                        quest_obj_desc4 = objective_result.Field<String>("objective_desc4");
                        quest_obj_amt4 = objective_result.Field<Int32>("objective_amount4");
                    }
                    else
                    {
                        MessageBox.Show("No Objective Data (#4)");
                    }
                    if (objective_result.Field<Int32>("objective_id5") != 0)
                    {
                        quest_obj_id5 = objective_result.Field<Int32>("objective_id5");
                        quest_obj_name5 = objective_result.Field<String>("objective_name5");
                        quest_obj_desc5 = objective_result.Field<String>("objective_desc5");
                        quest_obj_amt5 = objective_result.Field<Int32>("objective_amount5");
                    }
                    else
                    {
                        MessageBox.Show("No Objective Data (#5)");
                    }
                    if (objective_result.Field<Int32>("objective_id6") != 0)
                    {
                        quest_obj_id6 = objective_result.Field<Int32>("objective_id6");
                        quest_obj_name6 = objective_result.Field<String>("objective_name6");
                        quest_obj_desc6 = objective_result.Field<String>("objective_desc6");
                        quest_obj_amt6 = objective_result.Field<Int32>("objective_amount6");
                    }
                    else
                    {
                        MessageBox.Show("No Objective Data (#6)");
                    }*/

                    ui_updater.DoWork += (obj, x) => { NaviControl_Tab_Populator(3); };
                    ui_updater.RunWorkerAsync();
                }
            }
            else
            {
                MessageBox.Show("Quest ID Empty");
            }

            return "objective_info_loaded";
        }
        #endregion
    }
}
